package org.ariadne_eu.hcifetcher.mumeUtils;

import java.util.HashMap;
import java.util.Map;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;

import org.ariadne_eu.hcifetcher.rest.RestUtils;

@Path("/entries/answer")
public class Answer {
	
	@Path("/")
	@GET
	@Produces("application/json")
	public String getAnswersByQuestionID(@QueryParam("id") String id,
										 @QueryParam("studentid") String name,
										 @QueryParam("questionid") String questionid,
										 @QueryParam("offset") String offset,
										 @QueryParam("size") String size) {
		if(id != null)
			return RestUtils.getInstance().getEntityById(id).toString();
		int intoffset = 0, intsize = 1000;
		try{
			intoffset = Integer.parseInt(offset);
			intsize = Integer.parseInt(size);
		}catch (Exception e) {//can't parse, use default values
		}
		Map<String, Object> filter = new HashMap<String, Object>();
		filter.put("studentid", name);
		filter.put("questionid", questionid);
		return RestUtils.getInstance().JSONToString(RestUtils.getInstance().getEntriesJSON("Answer", filter, intoffset, intsize, "datestamp", false));
	}

}
